package edu.wata.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.wata.service.ArticleServiceImpl;
import edu.wata.service.iface.ArticleService;

@WebServlet("/articleType.servlet")
public class ArticleTypeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private ArticleService articleService = new ArticleServiceImpl();

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String typeId = null == request.getParameter("typeId") ? "0" : request.getParameter("typeId");
		if (0 == Integer.valueOf(typeId)) {
			request.getRequestDispatcher("views/editArticleType.jsp").forward(request, response);
		} else {
			request.setAttribute("articles", articleService.getArticleMap(typeId));
			request.getRequestDispatcher("views/articleType.jsp").forward(request, response);
		}

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
